package com.sunsharing.transport.api;

import com.sunsharing.common.Context;
import com.sunsharing.transport.Channel;
import com.sunsharing.transport.IoHandle;
import org.apache.log4j.Logger;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created with IntelliJ IDEA.
 * User: criss
 * Date: 13-4-11
 * Time: 下午2:52
 * To change this template use File | Settings | File Templates.
 */
public class ClientHandle implements IoHandle {
    Logger logger = Logger.getLogger(ClientHandle.class);
    @Override
    public void doConnected(Channel session) {

    }

    Map<String,Send> result = new ConcurrentHashMap<String,Send>();

    @Override
    public void run(Context context) {
        logger.info("收到结果报文："+context.getMsg().msg);

        Send send = result.get(context.getTaskId());
        if(send!=null)
        {
            send.addResult(context);
        }
    }

    public void addListener(String taskId,Send send)
    {
         result.put(taskId,send);
    }

    public void removeListener(String taskId)
    {
        result.remove(taskId);
    }
}
